import _path from 'path'
import _fs from 'fs-extra'
import { Folder } from './meta/Folder';
import { Text } from './meta/Text';
import { Scene } from './meta/Scene';
import { TypeScript } from './meta/TypeScript';
import { Atlas } from './meta/Atlas';
import { RawAsset } from './meta/RawAsset';

/*
* @Author: gaara  
* @Date: 2020-06-13 11:34:28  
*/

export class TypeMgr {

    types:RawAsset[] = [];


    register(cls: any) {
        this.types.push(cls);
    }

    getType(path: string): any {
        let ext = _path.extname(path);
        let isDirectory = _fs.statSync(path).isDirectory();
        if (isDirectory) {
            return Folder;
        }

        for (let iterator of this.types) {
            let exts:string[] = (iterator as any).defaultType();
            if(exts.includes(ext)){
                return iterator;
            }
        }
    
        return null;
    }
}

